<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="../tpl/header.html" /}
</head>
<body>
{include file="../tpl/menu.html" /}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    {if condition="check_auth('admin/admin/menuadd')"}
                    <button class="layui-btn" onclick="xadmin.open('添加','{:url('admin/admin/menuAdd')}')"><i class="layui-icon"></i>添加</button>
                    {/if}
                    <button class="layui-btn" onclick="show_menu(this)">隐藏非菜单</button>
                    <button class="layui-btn" onclick="menu_set(1)">全部展开</button>
                    <button class="layui-btn" onclick="menu_set(2)">全部关闭</button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <tbody>
                            <thead>
                            <tr>
                                <th width="80px">排序号</th>
                                <th width="80px">按钮</th>
                                <th>名称</th>
                                <th>url</th>
                                <th>是否是菜单</th>
                                <th>图标</th>
                                <th>操作</th>
                            </tr>
                            <thead>
                        <tbody class="x-cate">
                        {volist name="list" id="vo"}


                        <tr {if condition="$vo['is_menu'] neq 1"}class="is_menu"{/if} cate-id="{$vo.id}" fid="{$vo.pid}" >
                            <td width="80px">{$vo.mark}{$vo.sort}</td>
                            <td>
                                {if condition="$vo['url'] eq ''"}
                                <i class="layui-icon x-show" status='false'>&#xe625;</i>
                                {/if}
                            </td>
                            <td>
                                {if condition="$vo['pid'] eq 0"}
                                <span style="color:rgb(0,0,255);font-size: 18px;font-weight: bold;">{$vo.mark}{$vo.name}</span>
                                {elseif condition="$vo['url'] eq ''" /}
                                <span style="color:rgb(0,0,255);font-size: 15px;font-weight: bolder;">{$vo.mark}{$vo.name}</span>
                                {else/}
                                    {if condition="$vo['is_menu'] neq 1"}
                                <span style="color: #FF5722;font-size: 13px;font-weight: bolder;">{$vo.mark}{$vo.name}</span>
                                    {else/}
                                <span style="font-size: 13px;font-weight: bolder;">{$vo.mark}{$vo.name}</span>
                                    {/if}
                                {/if}
                            </td>
                            <td>{if condition="$vo['is_menu'] eq 1"}
                                <a title="点击跳转" href="/{$vo.url}" target="_blank" style="color: #1E9FFF;">{$vo.url}</a>
                                {else/}
                                {$vo.url}
                                {/if}
                            </td>
                            <td>
                                {if condition="$vo['is_menu'] eq 1"}
                                <span class="layui-btn layui-btn-normal layui-btn-mini">是</span>
                                {else/}
                                <span class="layui-btn layui-btn-danger layui-btn-mini">否</span>
                                {/if}
                            </td>
                            <td><i class="iconfont">{$vo.icon|raw}</i></td>
                            <td class="td-manage">
                                {if condition="check_auth('admin/admin/menuadd')"}
                                {if condition="$vo['url'] eq ''"}
                                <button title="添加子菜单" class="layui-btn" onclick="xadmin.open('添加子菜单','{:url('admin/admin/menuadd',['pid' => $vo['id']])}')">
                                    <i class="layui-icon"></i>添加
                                </button>
                                {/if}
                                {/if}
                                {if condition="check_auth('admin/admin/menuedit')"}
                                <button title="编辑" class="layui-btn layui-bg-blue" onclick="xadmin.open('编辑菜单','{:url('admin/admin/menuedit',['id' => $vo['id']])}')">
                                    <i class="layui-icon">&#xe642;</i>编辑
                                </button>
                                {/if}
                                {if condition="check_auth('admin/admin/menudel')"}
                                <button title="删除" class="layui-btn-danger layui-btn layui-btn-xs" onclick="del(this,'{$vo.id}','{:url('admin/admin/menudel')}')">
                                    <i class="layui-icon">&#xe640;</i>删除
                                </button>
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    // 分类展开收起的分类的逻辑
    $(function(){
        // $("tbody.x-cate tr[fid!='0']").hide();
        // 栏目多级显示效果
        $('.x-show').click(function () {
            if($(this).attr('status')=='true'){
                $(this).html('&#xe625;');
                $(this).attr('status','false');
                cateId = $(this).parents('tr').attr('cate-id');
                $("tbody tr[fid="+cateId+"]").show();
            }else{
                cateIds = [];
                $(this).html('&#xe623;');
                $(this).attr('status','true');
                cateId = $(this).parents('tr').attr('cate-id');
                getCateId(cateId);
                for (var i in cateIds) {
                    $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                }
            }
        })
    });

    //展开关闭菜单
    function menu_set(t) {
        switch (t){
            case 1:
                $("tbody.x-cate tr").show();
                break;
            case 2:
                $("tbody.x-cate tr[fid!='0']").hide();
                break;
        }
        return;
    }

    var cateIds = [];
    function getCateId(cateId) {
        $("tbody tr[fid="+cateId+"]").each(function(index, el) {
            id = $(el).attr('cate-id');
            cateIds.push(id);
            getCateId(id);
        });
    }


    function show_menu(obj) {
        $('.is_menu').each(function () {
            var css = $(this).css('display');
            if(css === 'none'){
                $(this).css('display','');
                $(obj).text('隐藏非菜单');
            }else{
                $(this).css('display','none');
                $(obj).text('显示非菜单');
            }
        });
    }

</script>
</body>
</html>